package com.copm.ifm.servers.sys.task;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.copm.ifm.base.basic.constant.DbConstants;
import com.copm.ifm.servers.sys.entity.SysProjectAuth;
import com.copm.ifm.servers.sys.service.project.SysProjectAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * @author tp
 */
@Component
public class ProjectOverdueTask {

    @Autowired
    SysProjectAuthService sysProjectAuthService;

    /**
     * 每天的0点执行一次
     * 跟当前时间相比较，将已经过期的项目授权的项目修改状态为已过期
     */
    @Scheduled(cron = "0 0 0 * * ?")
    public void printSay() {
        List<SysProjectAuth> list = sysProjectAuthService.list(new LambdaQueryWrapper<SysProjectAuth>()
                .eq(SysProjectAuth::getIsOverdue, DbConstants.DEFAULT_NO));
        list.stream().filter(s -> s.getAuthEndTime().before(new Date()))
                .forEach(x -> x.setIsOverdue(true));
        sysProjectAuthService.updateBatchById(list);
    }
}
